package com.zhubayi.controller;

import com.zhubayi.entity.Category;
import com.zhubayi.service.CategoryService;
import com.zhubayi.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author 祝八一
 */
@Controller
public class IndexController {
    @Autowired
    VideoService videoService;
    @Autowired
    CategoryService categoryService;
    @RequestMapping({"/","index"})
    public String index(Model model,Integer categoryId,String title){

        List<Category> categories = categoryService.queryAll();
        model.addAttribute("categories",categories);
        if (categoryId!=null){
            model.addAttribute("categoryId",categoryId);
        }
        if (title!=null&&!"".equals(title)){
            model.addAttribute("title",title);
        }
        model.addAttribute("pageInfo",videoService.getForIndex(categoryId,title));
        return "index";
    }
    @GetMapping("toReg")
    public String toReg(){
        return "Reg";
    }
    @GetMapping("toLogin")
    public String toLogin(){
        return "login";
    }


}
